/*
 * SplitMergeDAO.java
 *
 * Created on June 9, 2002, 1:59 PM
 */

package com.scalar.chiptrack.operations.splitmerge.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.scalar.ScalarException;
import com.scalar.chiptrack.db.DBTransaction;
import com.scalar.chiptrack.db.DataSource;
/**
 *
 * @author  Mallikarjun
 * @version 1.0
 */
public class SplitMergeDAO {

     public static void getSplitMergeInfo(DBTransaction dbt) throws ScalarException{
            Connection conn = null;
            PreparedStatement ps = null;
            boolean success = false;

            try {

                // Get the connection from regular datasource if its not in a manual transaction
                if (dbt == null) {
                    conn = DataSource.getConnection();
                }else {
                    conn = dbt.getConnection();
                }

                ps = conn.prepareStatement("");

                success = true;
            }catch (Exception sqle) {
                sqle.printStackTrace();
                throw new ScalarException ("Split/Merge operation failed", sqle);
            }finally {

                // Commit/Rollback here it selef -- if its not in a manual transaction
                if (dbt == null) {
                    try {
                        if (conn != null) {
                            if (success == true) {
                                conn.commit();
                            }
                            else {
                                conn.rollback();
                            }
                        }
                    }catch (SQLException ignore) {}
                }

                if (ps != null) {
                    try { ps.close(); } catch (SQLException ignore){}
                }
                if (conn != null) {
                    try { conn.close(); } catch (SQLException ignore){}
                }
            }
    }
    
    public static void storeLotSplitInfo(DBTransaction dbt) throws ScalarException{
            Connection conn = null;
            PreparedStatement ps = null;
            boolean success = false;

            try {

                // Get the connection from regular datasource if its not in a manual transaction
                if (dbt == null) {
                    conn = DataSource.getConnection();
                }else {
                    conn = dbt.getConnection();
                }

                ps = conn.prepareStatement("");

                success = true;
            }catch (Exception sqle) {
                sqle.printStackTrace();
                throw new ScalarException ("Lot Split operation failed", sqle);
            }finally {

                // Commit/Rollback here it selef -- if its not in a manual transaction
                if (dbt == null) {
                    try {
                        if (conn != null) {
                            if (success == true) {
                                conn.commit();
                            }
                            else {
                                conn.rollback();
                            }
                        }
                    }catch (SQLException ignore) {}
                }

                if (ps != null) {
                    try { ps.close(); } catch (SQLException ignore){}
                }
                if (conn != null) {
                    try { conn.close(); } catch (SQLException ignore){}
                }
            }
    }
  public static void storeLotMergeInfo(DBTransaction dbt) throws ScalarException{
            Connection conn = null;
            PreparedStatement ps = null;
            boolean success = false;

            try {

                // Get the connection from regular datasource if its not in a manual transaction
                if (dbt == null) {
                    conn = DataSource.getConnection();
                }else {
                    conn = dbt.getConnection();
                }

                ps = conn.prepareStatement("");

                success = true;
            }catch (Exception sqle) {
                sqle.printStackTrace();
                throw new ScalarException ("Lot Merge operation failed", sqle);
            }finally {

                // Commit/Rollback here it selef -- if its not in a manual transaction
                if (dbt == null) {
                    try {
                        if (conn != null) {
                            if (success == true) {
                                conn.commit();
                            }
                            else {
                                conn.rollback();
                            }
                        }
                    }catch (SQLException ignore) {}
                }

                if (ps != null) {
                    try { ps.close(); } catch (SQLException ignore){}
                }
                if (conn != null) {
                    try { conn.close(); } catch (SQLException ignore){}
                }
            }
    }

}
